<?php

/**
 * 
 */
class Admin_LocalController extends App_Controller_Default
{
	/** 
	 * 
	 * @var Model_Mapper_Local
	 */
	protected $_mapper;
	
	/** 
	 * 
	 * @var Admin_Form_Local
	 */
	protected $_form;
	
	/**
	 * (non-PHPdoc)
	 * @see Zend_Controller_Action::init()
	 */
    public function init()
    {
    	$this->view->noToolBar = true;
    	
    	$this->_mapper = new Model_Mapper_Local();
    }
    
	/**
     * 
     * @access 	protected
     * @param 	string $action
     * @return 	Admin_Form_Local
     */
    protected function _getForm ( $action )
    {
    	if ( is_null($this->_form) ) {
    		
    		$this->_form = new Admin_Form_Local();
    		$this->_form->setAction( $action );
    		
    	}
    	
    	return $this->_form;
    }
    
    /**
     * 
     * @access public
     * @return void
     */
    public function formPostHook()
    {
    	$this->view->form->setAction( $this->_helper->url('save-upload') );
    }
    
    /**
     * 
     * @access public
     * @return void
     */
    public function editPostHook()
    {
    	$this->view->form->setAction( $this->_helper->url('save-upload') );
    	
    	$id = $this->_getParam( 'id', 0 );
    	
    	$mapper = new Model_Mapper_Imagem();
    	$mapper->setData( array('lcl_id' => $id) );

    	$rows = $mapper->fetchImage();
    	
    	$image = array();
    	
        $i = 0;
    	foreach ( $rows as $row ) {
    	    $image[$i]['id'] = $row->img_id;
    	    $image[$i]['nome'] = $row->img_nome;
            $i++;
        }
        
        $this->view->image = $image;
    	
    	
    	
    }
}